package com.jiepos.mpos.biz.service.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.service.service.ServiceInfService;
import com.jiepos.mpos.biz.service.service.ServiceParamService;
import com.jiepos.mpos.common.entity.App_Service_InfEntity;
import com.jiepos.mpos.common.entity.App_Service_ParamEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;

/**
 * 业务参数维护Controller
 * @author Zhao.Jinkui
 * @version 1.0
 * @ProjectName: mpos
 * @Package com.jiepos.mpos.biz.service.controller
 * @ClassName serviceParamController
 * @history
 * @UpdateRemark []
 * @since 2017/9/24
 */
@Controller
@RequestMapping("serviceParam")
public class ServiceParamController extends BaseController {

    @Autowired
    private ServiceParamService serviceParamService;

    @Autowired
    private ServiceInfService serviceInfService;


    /**
     * 进入业务参数页面
     * @param request
     * @param response
     * @param pagination
     * @return
     */
    @RequestMapping("/getServiceParamList.do")
    public ModelAndView getServiceParamList(HttpServletRequest request, HttpServletResponse response,Pagination pagination){
        ModelAndView model = new ModelAndView("/module/service/serviceparam/serviceParam_list");
        return super.getDetail(request, response, model);
    }

    /**
     * 查询业务参数Json数据
     * @param pagination
     * @param appserviceParamEntity
     * @return
     */
    @RequestMapping("/getServiceParamListJson.do")
    public @ResponseBody Map getServiceParamListJson(Pagination pagination, App_Service_ParamEntity appserviceParamEntity,App_Service_InfEntity appServiceInfEntity){
        return serviceParamService.findByCondition(pagination,appserviceParamEntity,appServiceInfEntity);
    }

    /**
     * 根据uuid加载业务参数详情页面
     * @param request
     * @param response
     * @param service_param_uuid
     * @return
     */
    @RequestMapping("getServiceParamDetail.do")
    public ModelAndView getServiceParamDetail(HttpServletRequest request, HttpServletResponse response,String service_param_uuid){
        ModelAndView model = new ModelAndView("/module/service/serviceparam/serviceParam_detail");
        App_Service_ParamEntity entity = serviceParamService.findByUUID(service_param_uuid);
        model.addObject("serviceParamEntity",entity);
        return super.getDetail(request,response,model);
    }

    /**
     * 进入新增业务参数界面
     * @param request
     * @param response
     * @param pagination
     * @return
     */
    @RequestMapping("/getServiceParamAdd.do")
    public ModelAndView getServiceParamAdd(HttpServletRequest request, HttpServletResponse response,Pagination pagination){
        ModelAndView model = new ModelAndView("/module/service/serviceparam/serviceParam_detail");
        return super.getDetail(request, response, model);
    }

    @RequestMapping("/getAllService")
    public @ResponseBody List<Map<String, Object>> getAllService(String service_uuid){
        //查询所有的业务
        List<Map<String, Object>> allService = serviceInfService.findAllServiceName(service_uuid);
        return allService;
    }

    /**
     * 保存业务参数信息
     * @param request
     * @param response
     * @param entity
     * @return
     */
    @RequestMapping("/saveServiceParam.do")
    public ModelAndView saveServiceParam(HttpServletRequest request,HttpServletResponse response,App_Service_ParamEntity entity){
        serviceParamService.saveServiceParam(entity,super.getLoginUser(request, response));
        Map map=super.getLoginUser(request, response);
        return new ModelAndView(new RedirectView("getServiceParamList.do"), map);
    }

    /**
     * 检查业务参数编号是否已存在
     * @param entity
     * @return 不存在返回success，存在返回error
     */
    @RequestMapping("checkServiceParam")
    public @ResponseBody String checkServiceParam(App_Service_ParamEntity entity){
        return serviceParamService.checkService(entity);
    }

    /**
     * 启用/冻结 业务参数
     * @param request
     * @param response
     * @param serviceParam_st 要更新为的业务参数状态
     * @param service_param_uuids 哪些业务参数要更新
     * @return
     */
    @RequestMapping("/updateServiceParamSt.do")
    @ResponseBody
    public void updateServiceParamSt(HttpServletRequest request, HttpServletResponse response,String serviceParam_st, String service_param_uuids){
        serviceParamService.updateServiceParamSt(serviceParam_st,service_param_uuids, super.getLoginUser(request, response));
    }
    
    /**
     * 根据父级service_uuid获取具体业务参数，无父级业务uuid则获取所有业务参数数据
     * @param service_uuid
     * @return
     */
    @RequestMapping("/getAllServiceParams")
    public @ResponseBody List<Map<String, Object>> getAllServiceParams(String service_uuid){
        //查询所有的业务
        List<Map<String, Object>> allServiceParams = serviceParamService.findAllServiceParams(service_uuid);
        return allServiceParams;
    }

}
